//费用对账
interface IFeeCheckViewModel extends IBaseViewModel<IFeeCheckQueryTerms>{
    /**
     * ui-grid控制
     */
    gridOptions: uiGrid.IGridOptionsOf<FinanceFeeListItemResponse>;

    /**
     * 合同状态下拉
     */
    contractStatusDropDown:ValueListItemResponse[];
    /**
     * 油卡状态
     */
    oilCCardStatusDropDown:ValueListItemResponse[];
    /**
     * 回单状态
     */
    receiptStatusDropDown:ValueListItemResponse[];
    /**
     * 费用类型
     */
    feeTypeDropDown:ValueListItemResponse[];
    /**
     * 费用状态
     */
    feeStatusDropDown:ValueListItemResponse[];
    /**
     * 付款方式
     */
    paymentMethodDropDown:ValueListItemResponse[];
    /**
     * 选中后存入参数
     */
    onSelectedFeeInfo:selectedFeeData[];

    /**
     * 全选
     */
    selectAllEve():void;

    /**
     * 清空已选
     */
    emptySelected():void;
    /**
     * 退回审核
     */
    backAudit():void;
    /**
     * 新增费用单
     */
    shipAddFeeToParent():void;
    /**
     * 费用对账
     */
    shipCheckDetail():void;
    /**
     * 生成结算账单
     */
    shipCreateSettle():void;  
    /**
     * 导出
     */
    excelEvent():void;
    /**
     * 打印
     */
    printEvent():void;
    /**
     * 新增费用单权限btn
     */
    canAddFeeToParent:boolean;

    /**
     * 生成结算账单权限btn
     */
    canCreateSettle:boolean; 
    /**
     * 删除已选费用
     */
    feeSelectedDelet(arg:string):void;
    /**
     * 翻页后选中
     */
    resumeSelectedItem():void;

    
    heightA:number;
}

/**
 * 选中后存入参数
 */
interface selectedFeeData {
    /**
     * 费用id
     */
    id:string;
    /**
     * 费用编号
     */
    feeCode:string;
    /**
     * 付款方式
     */
    paymentMethod:string;
    /**
     * 费用状态
     */
    feeStatus:string;
    /**
     * 费用类型
     */
    feeType:string;
}


/**
 * 查询条件
 */
interface IFeeCheckQueryTerms{
    /**
     * 客户单位
     */
    clientName:string;
    /**
     * 申领人
     */
    applicant:string;
    /**
     * 合同短号
     */
    contractNumber:string;
    /**
     * 合同状态
     */
    contractStatus:string;
    /**
     * 发货起始时间
     */
    startDeliveryTime:string;
    /**
     * 发货结束时间
     */
    endDeliveryTime:string;
    /**
     * 油卡状态
     */
    oilCardStatus:string;
    /**
     * 承运商
     */
    carrierName:string;
    /**
     * 回单状态
     */
    receiptStatus:string;
    /**
     * 车牌号
     */
    carCode:string;
    /**
     * 费用类型
     */
    feeType:string;
    /**
     * 费用状态
     */
    feeStatusList:string;
    /**
     * 发货地址
     */
    origin:string;
    /**
     * 送货地址
     */
    destination:string;
    /**
     * 付款方式
     */
    paymentMethod:string;
    /**
     * 结算开始时间
     */
    startSettleTime:string;
    /**
     * 结算结束时间
     */
    endSettleTime:string;

    /**
     * 付款起始时间
     */
    payStartTime:string;
    /**
     * 付款结束时间
     */
    payEndTime:string;

}

class feeCheckController extends ListController<IFeeCheckViewModel,IFeeCheckQueryTerms>{
    gridApi: uiGrid.IGridApiOf<FinanceFeeListItemResponse>;

    lockSelect: boolean = false;
    orderBy: number = 0;
    asc: boolean = true;
    isSelectAll:boolean = false;

    constructor($scope: IFeeCheckViewModel,private authorizationService:IAuthorizationService,private routeService: routeService,private feeSerice:IFeeService,private orderService:IorderService, private valueService: IValueService, private $ngBootbox: BootboxService,private $state: angular.ui.IStateService,private loginService:ILoginService,private $timeout:ng.ITimeoutService,private LodopFuncsService:LodopFuncsService,private $location:ng.ILocationService,private exportService:IexportService) {
        super($scope);
        this.init();
    }

    init():void{
        super.init();

        this.$scope.queryTerms = {
            clientName:"",
            applicant:"",
            contractNumber:"",
            contractStatus:"",
            startDeliveryTime:"",
            endDeliveryTime:"",
            oilCardStatus:"",
            carrierName:"",
            receiptStatus:"",
            carCode:"",
            feeType:"",
            feeStatusList:"3",
            origin:"",
            destination:"",
            paymentMethod:"",
            startSettleTime:"",
            endSettleTime:"",
            payStartTime:"",
            payEndTime:""
        }
        
        this.$scope.gridOptions = {
			enableSelectAll: true,//全选开启
			enableRowSelection: true,
			enableRowHeaderSelection: false,
			paginationPageSizes: [10, 20, 30],
			useExternalPagination: true,
			useExternalSorting: true,
			enableColumnResizing: true,
            multiSelect:true,
            columnDefs: [
                            { displayName: "费用编号", field: 'feeCode', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.feeCode}}</div>', width: '10%' },
                            { displayName: '发货时间', field: 'shipTime', enableColumnMenu: false,  cellTemplate: '<div ng-repeat="item in row.entity.orderList" class="LTL-list" >{{item.shipTime}}</div>', width: '8%' },
                            { displayName: "合同号", field: 'contractNumber', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.contractNumber}}</div>' },
                            { displayName: "发货地址", field: 'startAddress', enableColumnMenu: false, enableSorting: false, cellTemplate: '<div ng-repeat="item in row.entity.orderList" class="LTL-list">{{item.startAddress}}</div>', width: '10%' },
                            { displayName: '送货地址', field: 'endAddress', enableColumnMenu: false, enableSorting: false, cellTemplate: '<div ng-repeat="item in row.entity.orderList" class="LTL-list" >{{item.endAddress}}</div>', width: '10%' },
                            { displayName: '货物数量', field: 'goodsNum', enableColumnMenu: false, enableSorting: false, cellTemplate: '<div ng-repeat="item in row.entity.orderList" class="LTL-list" >{{item.goodsNum}}</div>', width: '10%' },
                            { displayName: "客户单位", field: 'clientName', enableColumnMenu: false, enableSorting: false, cellTemplate: '<div ng-repeat="item in row.entity.orderList" class="LTL-list" >{{item.clientName}}</div>' },
                            { displayName: '回单状态', field: 'receiptStatus', enableColumnMenu: false, cellTemplate: '<div ng-repeat="item in row.entity.orderList" class="LTL-list" >{{item.receiptStatus}}</div>' },
							{ displayName: '合同状态', field: 'contractStatus', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.contractStatus}}</div>' },
							{ displayName: '承运商', field: 'carrier', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.carrier}}</div>' },
							{ displayName: '车牌号', field: 'carCode', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.carCode}}</div>' },
							{ displayName: '付款方式', field: 'paymentMethod', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.paymentMethod}}</div>' },
							{ displayName: '费用类型', field: 'feeType', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.feeType}}</div>' },
                            { displayName: '费用金额', field: 'feeAmount', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.feeAmount}}</div>' },
							{ displayName: '费用状态', field: 'feeStatus', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.feeStatus}}</div>' },
							{ displayName: '结算日期', field: 'settleTime', enableColumnMenu: false, cellTemplate: '<div style="height:{{39 * row.entity.orderList.length}}px;"class="single-list">{{row.entity.settleTime}}</div>', width: '9%' }
                ],
            onRegisterApi: (gridApi) => {
                this.gridApi = gridApi;
                gridApi.pagination.on.paginationChanged(this.$scope, this.paginationChanged);
                gridApi.core.notifyDataChange("options");
                gridApi.core.on.sortChanged(this.$scope, this.sortChange);
                gridApi.selection.on.rowSelectionChanged(this.$scope, (row)=>{this.selectChange(row,this.$scope.gridOptions.data)});
            }
        }

        this.$scope.onSelectedFeeInfo = [];
        this.$scope.canCreateSettle = false;
        this.$scope.canAddFeeToParent = false;
        this.getAuthority();

        this.query();
        this.$scope.selectAllEve = ()=>{this.selectAllEve(this.$scope.gridOptions.data)};

        this.$scope.emptySelected = this.emptySelected;

        this.$scope.backAudit = this.backAudit;

        this.$scope.shipAddFeeToParent = this.shipAddFeeToParent;

        this.$scope.shipCheckDetail = this.shipCheckDetail;

        this.$scope.shipCreateSettle = this.shipCreateSettle;  

        this.LodopFuncsService.getRoute(this.routeService.print.url);
        this.$scope.printEvent = this.printEvent;

        this.$scope.feeSelectedDelet = (id)=>{this.feeSelectedDelet(id,this.$scope.gridOptions.data)};

        this.loadDropDown();
        /*datetimepicker*/
		$('#openstartDeliveryTime').click(function () {
		    $('#startDeliveryTime').datetimepicker('show');
		});
		$('#openendDeliveryTime').click(function () {
		    $('#endDeliveryTime').datetimepicker('show');
		});
		$('#openstartSettleTime').click(function () {
		    $('#startSettleTime').datetimepicker('show');
		});
		$('#openendSettleTime').click(function () {
		    $('#endSettleTime').datetimepicker('show');
		});


    }

    /**
     * 加载数据
     */
    loadData(queryTerms:IFeeCheckQueryTerms,skip:number,count:number):void{
        if(queryTerms.feeStatusList == "" || !queryTerms.feeStatusList){queryTerms.feeStatusList = "1,2,3,4,5,6,7,8,9,10,11";}
        let feeStatusList = queryTerms.feeStatusList
        if(queryTerms.feeStatusList == "10"){ feeStatusList = "10,11";}
        this.feeSerice.getFinanceFeeList(this.orderBy.toString(),this.asc,"","",queryTerms.clientName,"",queryTerms.applicant,queryTerms.contractNumber,queryTerms.startDeliveryTime,queryTerms.endDeliveryTime,"","",queryTerms.startSettleTime,queryTerms.endSettleTime,queryTerms.payStartTime,queryTerms.payEndTime,queryTerms.contractStatus,queryTerms.receiptStatus,queryTerms.oilCardStatus,"",queryTerms.carrierName,"",queryTerms.carCode,queryTerms.feeType,feeStatusList,queryTerms.origin,queryTerms.destination,queryTerms.paymentMethod,"",skip,count).then(result=>{
            // this.$scope.gridOptions.totalItems = result.data.extData;
            this.$scope.gridOptions.data = result.data.data;
            let gridHArr = 0;
            result.data.data.forEach((item,index) => { gridHArr =  gridHArr + item.orderList.length; });
            this.$scope.heightA = (gridHArr*39)+96;
            if(skip==0){ this.$scope.gridOptions.paginationCurrentPage = 1; };
            this.resumeSelectedItem(this.$scope.gridOptions.data);
            this.$scope.querying = false;
        },error=>{this.$scope.querying = false});
    }


    getListCount():void{
        if(this.$scope.queryTerms.feeStatusList == "" || !this.$scope.queryTerms.feeStatusList){this.$scope.queryTerms.feeStatusList = "1,2,3,4,5,6,7,8,9,10,11";}
        let feeStatusList = this.$scope.queryTerms.feeStatusList
        if(this.$scope.queryTerms.feeStatusList == "10"){ feeStatusList = "10,11";}

        this.feeSerice.getFinanceFeeCount("","",this.$scope.queryTerms.clientName,"",this.$scope.queryTerms.applicant,this.$scope.queryTerms.contractNumber,this.$scope.queryTerms.startDeliveryTime,this.$scope.queryTerms.endDeliveryTime,"","",this.$scope.queryTerms.startSettleTime,this.$scope.queryTerms.endSettleTime,this.$scope.queryTerms.payStartTime,this.$scope.queryTerms.payEndTime,this.$scope.queryTerms.contractStatus,this.$scope.queryTerms.receiptStatus,this.$scope.queryTerms.oilCardStatus,"",this.$scope.queryTerms.carrierName,"",this.$scope.queryTerms.carCode,this.$scope.queryTerms.feeType,feeStatusList,this.$scope.queryTerms.origin,this.$scope.queryTerms.destination,this.$scope.queryTerms.paymentMethod,"").then(res=>{
            this.$scope.gridOptions.totalItems = res.data.extData;
        })
    }


    
    localHistory():void{
        super.localHistory(this.$state)
    }
    getHistory():void{
        super.getHistory(this.$state,this.$location)
    }


    /**
     * 排序触发Event
     */
    sortChange=(grid: uiGrid.IGridInstanceOf<FinanceFeeListItemResponse>, sortColumns: Array<uiGrid.IGridColumnOf<FinanceFeeListItemResponse>>)=>{
        if (sortColumns.length == 0) {
           this.reload();
        } else {
            let sortItem = sortColumns[0];
            switch (sortItem.name) {
                case "feeCode": {
                    this.orderBy = 1;
                } break;
                case "contractNumber": {
                    this.orderBy = 3;
                } break;
                case "shipTime": {
                    this.orderBy = 5;
                } break;
                case "startAddress": {
                    this.orderBy = 6;
                } break;
                case "endAddress": {
                    this.orderBy = 7;
                } break;
                case "contractStatus": {
                    this.orderBy = 12;
                } break;
                case "carrier": {
                    this.orderBy = 14;
                } break;
                case "carCode": {
                    this.orderBy = 11;
                } break;
                case "feeType": {
                    this.orderBy = 19;
                } break;
                case "feeAmount": {
                    this.orderBy = 15;
                } break;
                case "feeStatus":{
                    this.orderBy = 13;
                }break;
                case "applicant": {
                    this.orderBy = 18;
                } break;
                case "receiptStatus": {
                    this.orderBy = 9;
                } break;
            }
            this.asc = sortItem.sort.direction == "asc";
            this.reload();
        }
    }

    /**
     * 选择事件
     */
    selectChange=(row:uiGrid.IGridRowOf<FinanceFeeListItemResponse>,data:string | FinanceFeeListItemResponse[])=>{
        if(this.lockSelect){return;};
        if(row.isSelected){
            this.$scope.onSelectedFeeInfo.push({
                id:row.entity.id,
                feeCode:row.entity.feeCode,
                paymentMethod:row.entity.paymentMethod,
                feeStatus:row.entity.feeStatus,
                feeType:row.entity.feeType
            });
            if(!this.isSelectAll){
                if(this.$scope.onSelectedFeeInfo.length > 1){
                    let passed = this.$scope.onSelectedFeeInfo.every(this.isPaymentPass)
                    if(!passed){
                        this.$ngBootbox.alert("付款方式必须一致");
                        if(this.isfeeListResponse(data)){
                            data.forEach((item,index)=>{
                                if (row.entity.id == item.id) {
                                    if(this.isfeeListResponse(data)){
                                        this.gridApi.selection.unSelectRow(data[index]);
                                    }
                                }
                            })
                        }
                    }
                }
            }
        }else{
            this.$scope.onSelectedFeeInfo.forEach((item,index)=>{
                if(row.entity.id === item.id){
                    this.$scope.onSelectedFeeInfo.splice(index,1);
                }
            });
        }
    }

    
    /**
     * 删除选中费用
     */
    feeSelectedDelet=(arg:string,data:string | FinanceFeeListItemResponse[])=>{
        this.$scope.onSelectedFeeInfo.forEach((item,index)=>{
            if(arg === item.id){
                this.$scope.onSelectedFeeInfo.splice(index,1);
                if(this.isfeeListResponse(data)){
                    data.forEach((items,indexs)=>{
                        if(item.id == items.id){
                            if(this.isfeeListResponse(data)){
                                this.gridApi.selection.unSelectRow(data[indexs]);
                            }
                        }
                    });
                }
            }
        });
    }

    //断言
    isfeeListResponse(response: string | FinanceFeeListItemResponse[]): response is FinanceFeeListItemResponse[] {
        return (<FinanceFeeListItemResponse[]>response).forEach !== undefined;
    }
    /**
     * 翻页后选中
     */
    resumeSelectedItem(data:string | FinanceFeeListItemResponse[]):void{
        if(this.$scope.onSelectedFeeInfo.length <1){return};
        if(this.isfeeListResponse(data)){
            data.forEach((item,index)=>{
                this.$scope.onSelectedFeeInfo.forEach((itemS,indexS)=>{
                    if(item.id === itemS.id){
                        this.$timeout(()=>{
                            if(this.isfeeListResponse(data)){
                                this.lockSelect = true;
                                this.gridApi.selection.selectRow(data[index]);
                                this.lockSelect = false;
                            }
                        });
                    }
                });
            })
        }
    }

    /**
     * 全选
     */
    selectAllEve=(data:string | FinanceFeeListItemResponse[])=>{
        if(this.isfeeListResponse(data)){
            this.isSelectAll = true;
            data.forEach((item,index)=>{
                 if(this.isfeeListResponse(data)){
                    this.gridApi.selection.selectRow(data[index]);
                 }
            })
            this.isSelectAll = false;
        }
    }
    /**
     * 清空已选
     */
    emptySelected=()=>{
        this.gridApi.selection.clearSelectedRows();
        this.$scope.onSelectedFeeInfo.length = 0;
    }

    /**
     * 退回审核
     */
    backAudit=()=>{
        let onSInfo = this.$scope.onSelectedFeeInfo;
        if(onSInfo.length > 1){
            this.$ngBootbox.alert("只能选择单笔退回审核")
        }else if(onSInfo.length < 1){
            this.$ngBootbox.alert("请选择一笔进行退回审核")
        }else if(onSInfo.length === 1){
            this.feeSerice.feeDetail(onSInfo[0].id).then(res=>{
                if(res.data.feeStatus === "3" || res.data.feeStatus === "5"){
                    this.$ngBootbox.confirm("确定退回审核吗").then(res=>{
                        this.feeSerice.returnManage(onSInfo[0].id).then(res=>{
                           this.$scope.gridOptions.paginationCurrentPage = 1;
                           onSInfo.length = 0;
                           if(!this.queryTerms.feeStatusList){
                                this.queryTerms.feeStatusList = "1,2,3,4,5,6,7,8,9,10,11"
                           }
                            this.query();
                        });
                    })
                }else{this.$ngBootbox.alert("只有待结算和退回结算的费用才能退回审核")};
            })
        }
    }

    /**
     * 跳转新增费用单
     */
    shipAddFeeToParent=()=>{
        let onSInfo = this.$scope.onSelectedFeeInfo;
        if(onSInfo.length > 1){
            this.$ngBootbox.alert("只能选择单笔新增费用单");
        }else if(onSInfo.length < 1){
            this.$ngBootbox.alert("请选择一笔新增费用单");
        }else if(onSInfo.length === 1){
            this.feeSerice.feeDetail(onSInfo[0].id).then(res=>{
                if(res.data.feeStatus === "3" || res.data.feeStatus === "5"){
                    this.$state.go("app.fee.feeAddToParent", { id:onSInfo[0].id, code: onSInfo[0].feeCode });
                }else{this.$ngBootbox.alert("只有待结算和退回结算的费用才能新增到账单")};
            })
        }
    };

    /**
     * 跳转费用对账
     */
    shipCheckDetail=()=>{
        let onSInfo = this.$scope.onSelectedFeeInfo;
        if(onSInfo.length > 1){
            this.$ngBootbox.alert("只能选择一条费用对账");
        }else if(onSInfo.length < 1){
            this.$ngBootbox.alert("请选择一条费用对账");
        }else if(onSInfo.length === 1){
            this.feeSerice.feeDetail(onSInfo[0].id).then(res=>{
                let data = res.data;
                this.orderService.carryOrder(data.carrierOrderId).then(result=>{
                    if(result.data.orderList.length>1){
                        this.$state.go("app.fee.feeBreakbulkDetail", { feeId: onSInfo[0].id, carrierOrderId: data.carrierOrderId, pageName: 'Checking',feeStatus:onSInfo[0].feeStatus })
                    }else{
                        this.$state.go("app.fee.feeOrderDetailController", { feeId: onSInfo[0].id, orderId: result.data.orderList[0], carrierOrderId: data.carrierOrderId, name: 'Checking' })
                    }
                })
            })
        }
    };

    /**
     * 跳转结算单生成页面
     */
    shipCreateSettle=()=>{
        let ispass = true;
        if(this.$scope.onSelectedFeeInfo.length <1){ this.$ngBootbox.alert("请选择一笔生成结算单");return}
        for(let i=0;i<this.$scope.onSelectedFeeInfo.length;i++){
            if(!(this.$scope.onSelectedFeeInfo[i].feeStatus === "待结算" || this.$scope.onSelectedFeeInfo[i].feeStatus === "退回结算")){
                this.$ngBootbox.alert("只有待结算和退回结算的费用才能生成账单");
                ispass = false;
                break;
            }else{ ispass = true; }
        }



        if(ispass){
            if(this.$scope.onSelectedFeeInfo.every(this.isPaymentPass)){
                this.$ngBootbox.confirm("确定生成结算单吗").then(()=>{
                    var feeIdList = [],feeCodeList = [];
                    this.$scope.onSelectedFeeInfo.forEach((item,index)=>{
                        feeIdList.push(item.id);
                        feeCodeList.push(item.feeCode);
                    })
                    this.$state.go("app.fee.feeAddSettle", { feeIdList: feeIdList.join(","), codeList: feeCodeList});
                })
            }else{
                this.$ngBootbox.alert("付款方式必须相同");
            }
        }
       
    }
    /**
     * 导出
     */
    exportFunc=()=>{
        if(this.$scope.gridOptions.totalItems>60000){
            this.$ngBootbox.alert('导出数据不可超过6万条');
            return;
        }else{
            if(this.$scope.queryTerms.feeStatusList == "" || !this.$scope.queryTerms.feeStatusList){this.$scope.queryTerms.feeStatusList = "1,2,3,4,5,6,7,8,9,10,11";}
            let feeStatusList = this.$scope.queryTerms.feeStatusList
            if(this.$scope.queryTerms.feeStatusList == "10"){ feeStatusList = "10,11";}
            this.exportService.export(this.orderBy,this.asc,"","",this.queryTerms.clientName,"",this.queryTerms.applicant,this.queryTerms.contractNumber,this.queryTerms.startDeliveryTime,this.queryTerms.endDeliveryTime,"","",
            this.queryTerms.startSettleTime,this.queryTerms.endSettleTime,this.queryTerms.payStartTime,this.queryTerms.payEndTime,this.queryTerms.contractStatus !=null ? this.queryTerms.contractStatus : "",this.queryTerms.receiptStatus !=null ? this.queryTerms.receiptStatus : "",this.queryTerms.oilCardStatus !=null ? this.queryTerms.oilCardStatus : "",
            "",this.queryTerms.carrierName,"",this.queryTerms.carCode,this.queryTerms.feeType !=null ? this.queryTerms.feeType : "",feeStatusList,this.queryTerms.origin,this.queryTerms.destination,this.queryTerms.paymentMethod !=null ? this.queryTerms.paymentMethod : "")
        }
    }

    /**
     * 打印
     */
    // print=()=>{
    //     this.LodopFuncsService.getRoute(this.routeService.print.url);
    //     this.printEvent;
    // }

    printEvent=()=>{
        let feeInfo = this.$scope.onSelectedFeeInfo;
        if(feeInfo.length <1){this.$ngBootbox.alert("请选择一项进行打印"); return;}else if(feeInfo.length > 1){this.$ngBootbox.alert("只能选择单笔费用打印"); return;};
        this.feeSerice.feeVoucher(feeInfo[0].id).then((res)=>{
            this.getPrint(res.data,feeInfo[0].feeType);
        });   
    }


    //报销
    getReimbursement(time, holderName, bankCode, feetype, feeAmount, remark, feeAmountStr):void{
            LODOP.SET_SHOW_MODE("BKIMG_WIDTH", 100);
		    LODOP.PRINT_INIT("打印");
		    LODOP.ADD_PRINT_TEXT(84, 555, 140, 22, time);//审核时间
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);//居中
		    LODOP.ADD_PRINT_TEXT(152, 50, 99, 28, holderName);//持卡人姓名
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		    LODOP.ADD_PRINT_TEXT(152, 152, 182, 41, bankCode);//银行卡号
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		    LODOP.ADD_PRINT_TEXT(152, 513, 152, 29, feetype);//付款方式
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		    LODOP.ADD_PRINT_TEXT(192, 263, 225, 29, feeAmountStr);//报销金额(大写)
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.ADD_PRINT_TEXT(191, 539, 128, 27, feeAmount);//报销金额
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.ADD_PRINT_TEXT(223, 158, 524, 50, remark);//事由
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
    }

    /**
     * 领款
     */
    getDrawMoney(time, feetype, oilCarNum, reimbursementMoney, remark, feeAmountStr):void{
		    LODOP.SET_SHOW_MODE("BKIMG_WIDTH", 100);
		    LODOP.PRINT_INIT("打印");
		    LODOP.ADD_PRINT_TEXT(84, 552, 145, 27, time);//审核时间
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);//居中
		    LODOP.ADD_PRINT_TEXT(152, 361,319, 34, oilCarNum);//油卡卡号
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		    LODOP.ADD_PRINT_TEXT(153, 71, 248, 28, feetype);//付款方式
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		    LODOP.ADD_PRINT_TEXT(192, 273, 233, 24, feeAmountStr);//报销金额(大写)
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.ADD_PRINT_TEXT(192, 536, 134, 25, reimbursementMoney);//报销金额
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		    LODOP.ADD_PRINT_TEXT(223, 168, 511, 50, remark);//事由
		    LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
    }

    /**
     * 打印func
     */
    getPrint(data:FeeVoucherResponse,feeType:string):void{
        if(feeType !="预付款"){
            var imgUrl = this.routeService.print.reimbursement;
            this.getReimbursement(data.auditedTime,data.holder,data.bankCode,data.paymentMethod,data.feeAmount,data.description,data.feeAmountStr)
        }else{
            var imgUrl = this.routeService.print.drawMoney;
            this.getDrawMoney(data.auditedTime, data.paymentMethod, data.oilCardNumber, data.feeAmount, data.description, data.feeAmountStr);
        }
        LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0' src="+imgUrl+">");
        LODOP.SET_SHOW_MODE("BKIMG_PRINT", 1);
        LODOP.SET_PREVIEW_WINDOW(1, 0, 0, 950, 700, "");
        LODOP.SET_SHOW_MODE("HIDE_DISBUTTIN_SETUP", 1);//隐藏那些无效按钮
        LODOP.SET_PRINT_MODE("AUTO_CLOSE_PREWINDOW", 1);//打印后自动关闭预览窗口
        LODOP.PREVIEW();//打印模式
    }

    //判断费用状态是否一致
    isPaymentPass(item:selectedFeeData,index:number,array:selectedFeeData[]):boolean{
        if(array[0].paymentMethod === "石化油卡"&& item.paymentMethod === "石油油卡" || array[0].paymentMethod === "石油油卡"&& item.paymentMethod === "石化油卡"){
            return true;
        }
        return (item.paymentMethod === array[0].paymentMethod)
    }

    //添加费用至结算总单权限 - 添加费用至结算总单权限
    getAuthority():void{
		this.authorizationService.auth("24E0A026891BC3908E6AD176CAFEC50D98A1E3FBC0CAD1B2").then((res)=>{
			this.$scope.canAddFeeToParent = res.data.extData;
		});
        this.authorizationService.auth("24E0A026891BC390C69586073647CDA7").then((res)=> {
			this.$scope.canCreateSettle = res.data.extData;
		});
    };


    /**
     * 加载枚举
     */
    loadDropDown():void{
        let contractStatusDropDown = this.valueService.getContractStatusList().data;
        contractStatusDropDown.splice(0,1);
        this.$scope.contractStatusDropDown =contractStatusDropDown
        this.$scope.oilCCardStatusDropDown =  this.valueService.getOilCCardStatusList().data;

        this.$scope.feeTypeDropDown = this.valueService.getFeeTypeList().data;
        this.$scope.receiptStatusDropDown = this.valueService.getReceiptStatusList().data;
        this.$scope.feeStatusDropDown = this.valueService.getFeeStatusList().data;
        this.$scope.paymentMethodDropDown = this.valueService.getPaymentMethodList().data;
    }
}

angular.module("tms").controller("feeCheckController",["$scope","authorizationService","routeService","feeService","orderService","valueService","$ngBootbox","$state","loginService","$timeout","LodopFuncsService","$location","exportService",feeCheckController])

